package com.sas.hnn;

import java.util.Arrays;

import android.app.Activity;
import android.app.ListFragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.AdapterView.OnItemClickListener;

/**
 * Zeigt die Liste an. Nachdem die Liste sortiert wurde, wird der Adapter neu
 * gelesen (refresh()).
 */
public class PersonList extends ListFragment implements OnItemClickListener {

	private String TAG = PersonList.class.getSimpleName();

	private PersonAdapter mPersAdapter;
	private View mContext;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mContext = inflater.inflate(R.layout.person_list_row, null);
		refresh();
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	private void refresh() {
		setListAdapter(mPersAdapter);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		mPersAdapter = new PersonAdapter(activity);
	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		Log.d(TAG, "press the button" + arg2 + "," + arg3);
	}

	public boolean sort() {
		boolean res = mPersAdapter.sort();
		refresh();
		return res;
	}

	public boolean filterAge() {
		boolean res = mPersAdapter.filterAge();
		refresh();
		return res;
	}

}
